package kr.hkit.androidcomplete01.ch14;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.util.AttributeSet;
import android.widget.EditText;

public class SoundEdit extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		setContentView(R.layout.ch14_soudedit);
		
	}
	
	public class SoundEditWidget extends EditText {
		SoundPool mPool = null;
		int mClick;
		
		public SoundEditWidget(Context context) {
			super(context);
			init(context);
		}

		public SoundEditWidget(Context context, AttributeSet attrs) {
			super(context, attrs);
			init(context);
		}
		
		public SoundEditWidget(Context context, AttributeSet attrs, int defStyle) {
			super(context, attrs, defStyle);
			init(context);
		}

		void init(Context context) {
			mPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
			mClick = mPool.load(context, R.raw.click, 1);
		}

		protected void onTextChanged(CharSequence text, int start, int before, int after){
			if(mPool != null){
				mPool.play(mClick, 1, 1, 0, 0, 1);
			}
		}
	}
}
